<template>
  <div class="app">
    <h2 ref="test">我是App组件</h2>
    <button @click="showH2">点我打印h2</button>
    <button @click="testShow">测试一下ref用在组件标签</button>
    <br>
    <Person ref="ren"/>
  </div>
</template>

<script>
  import Person from './components/Person.vue'
  export default {
    name:'App',
    components:{Person},
    data() {
      return {
        x:100
      }
    },
    methods: {
      showH2(){
        // 下面这行代码中的this是App组件的实例对象（App的vc）
        console.log(this.$refs.test)
      },
      testShow(){
        // console.log(this) //打印的是App的实例
        console.log(this.$refs.ren) //打印的是Person的实例
        // this.$refs.ren.personAge = 999
      }
    },
  }
</script>

<style>
  .app {
    background-color: #ddd;
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 0 10px;
  }
</style>